<?php
	// API Key
	define("KEY", "gi6mmn5fmidijlc9thyhokl8z0fdtby9t4wgs2wek9");
	header("Content-Type: text/html; charset=utf-8");

	// API Target
	$url = "http://api-pub.dictionary.com/v001";

	// Receive parameters sent from HTML page
	if (isset($_GET["q"])) {
		$query = trim($_GET["q"]);
	}
	$encodedquery = urlencode($query);
	if (isset($_GET["type"])) {
		$type = trim($_GET["type"]);
	}
	
	$urlWithParam = $url."?vid=".KEY."&q=".$encodedquery."&type=".$type;

	/*
	 * you can change the following line with 
	 *		$data = @simplexml_load_file($urlWithParam) or die("no connection");
	 * as you need to manipulate XML result.
	 */
	$data = file_get_contents($urlWithParam);
	echo $data;
?>
